package com.wits.platform.common.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

public class WitsExceptionHandler implements HandlerExceptionResolver {
	
    protected final Logger log = LoggerFactory.getLogger(getClass());
	@Override
	public ModelAndView resolveException(HttpServletRequest request,HttpServletResponse response, Object handler, Exception ex) {
		if(handler instanceof HandlerMethod){
			HandlerMethod handlerMethod=(HandlerMethod)handler;
			String bean=handlerMethod.getBean().toString();
			String method=handlerMethod.getMethod().getName();
			log.error(String.format("error bean : %1s method : %2s", bean,method),ex);
		}else{
			log.error("error ", ex);
		}
		return null;
//		Map<String, Object> model = new HashMap<String, Object>();
//		model.put("exception", ex);
//		if(ex instanceof ServiceException) {
//			return new ModelAndView("error/service_error", model);
//		} else {
//			return new ModelAndView("error", model);
//		}
	}

}
